package cn.kgc.waimai.controller;


import cn.kgc.waimai.pojo.Cuisines;
import cn.kgc.waimai.pojo.Shjia;
import cn.kgc.waimai.service.CuisinesService;
import cn.kgc.waimai.service.ShjiaService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 陈啸
 * @create 2020-04-03 2:53
 */
@Controller
public class ShjiaController {
    @Resource
    ShjiaService businessService;

    @Resource
    CuisinesService cuisinesService;


    @RequestMapping("/toSelShj")
    public String getshj(){
        return "redirect:/selbusiness";
    }
    /*
     *Business
     *分页查询
     */
    @RequestMapping("/selbusiness")
    public String selbusiness(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                              @RequestParam(value = " pageSize", defaultValue = "4", required = false) Integer pageSize,
                              @RequestParam(value = "keyword", defaultValue = "", required = false) String keyword, Model model) {
        PageHelper.startPage(pageNum, pageSize);
        PageHelper.orderBy("id");
        List<Shjia> blogs = businessService.SelectBusiness(keyword);
        PageInfo<Shjia> pageInfo = new PageInfo(blogs);
        model.addAttribute("pageInfo", pageInfo);
        return "index";
    }
    /*根据id查看详情*/
    @RequestMapping("/SelectBusinessById")
    public String SelectBusinessById(int id, Model model) {
        Shjia business = businessService.SelectBusinessById(id);
        model.addAttribute("business", business);
        return "xiangqing";
    }

    //菜系列表
    @RequestMapping("/getSelect")
    public String getSelectCui(Model model){
        List<Cuisines> list=cuisinesService.getSelect();
        model.addAttribute("cuisines",list);
        return"index-main";
    }
}
